precision mediump float;

//const vec3 red = vec3(1.0,0.0,0.0);
//const vec3 blue = vec3(0.0,0.0,1.0);
//const float near = 0.1;
//const float far = 1000.0;
//varying vec4 v_posInView;

uniform float near;
uniform float far;

void main() {


//    gl_FragColor = vec4(vec3(gl_FragCoord.z), 1.0);

    // 转换成线性
    float z = gl_FragCoord.z;
    float srcZ = (near * far)/(z * near + far * (1.0 - z));
    float linearDepth = (srcZ - near) / (far - near);
    gl_FragColor = vec4(vec3(linearDepth),1.0);

    // gl_FragColor = vec4(vec3(pow(gl_FragColor.z, 20.0)), 1.0);

//    float z = v_posInView.z/v_posInView.w;
//    float linearDepth = (2.0 * near * far)/(far + near - z * (far - near));
//    gl_FragColor = vec4(vec3(linearDepth),1.0);

//    if(depthValue > 0.99){
//        gl_FragColor = vec4(red,1.0);
//    }else{
//        gl_FragColor = vec4(blue,1.0);
//    }
}
